package com.zxm.sunshineaiary.util;

import java.lang.reflect.InvocationTargetException;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.zxm.sunshineaiary.info.DateInfo;
import com.zxm.sunshineaiary.sql.service.SqlService;

public class SystemUtil {

	/**
	 * 2.2下关闭整个App包，可以完全退出App。需要传入context,Package包名。
	 * 
	 * @param context
	 * @param Package
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws SecurityException
	 * @throws NoSuchMethodException
	 */
	public static void closeAppNew(Context context) {
		Intent startMain = new Intent(Intent.ACTION_MAIN);
		startMain.addCategory(Intent.CATEGORY_HOME);
		startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(startMain);
		System.exit(0);
	}

	/**
	 * 分别删除SD卡上和SQL上的数据信息
	 * 
	 * @param context
	 * @param info
	 */
	public static void deleteDiary(Context context, DateInfo info) {
		SqlService sql = SqlService.getInstance(context);

		int year = Integer.parseInt(info.year);
		int month = Integer.parseInt(info.month);
		int day = Integer.parseInt(info.day);

		String date = CharsUtil.stringToDate(year, month, day);
		if (sql.deleteDiary(date)) {
			StorageFile.getInsance().deleteFile(info);
		}
	}
	
	public static void setBackground(Context context){
//		context.getw
	}
}
